		TITLE PUBDEF - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	SYMBOLS
		INCLUDE	SEGMENTS
		INCLUDE	CDDATA

		PUBLIC	PUBDEF,PUBDEF32,LPUBDF32,LPUBDF


		.DATA

		EXTERNDEF	PUB_SIZE:BYTE,PUB_TYPE:BYTE

		EXTERNDEF	SYM_HASH_MOD:DWORD,DEFAULT_SIZE:DWORD,CURNMOD_GINDEX:DWORD,PUB_FRAME:DWORD,PUB_GROUP_GINDEX:DWORD
		EXTERNDEF	PUB_SEGMOD_GINDEX:DWORD

		EXTERNDEF	GROUP_LARRAY:LARRAY_STRUCT,SEGMOD_LARRAY:LARRAY_STRUCT,SEGMOD_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	ERR_RET:PROC,DO_DEFINE_MODULE:PROC,PUB_CHECK:PROC

		EXTERNDEF	MUST_HAVE_SEGMENT_ERR:ABS,CONST_FRAME_ERR:ABS


LPUBDF		PROC
if	fg_phar
		MOV	AL,BPTR DEFAULT_SIZE	;IN CASE OF PHARLAP
else
		XOR	AL,AL
endif
LPUBDF1		LABEL	PROC

		MOV	ECX,CURNMOD_GINDEX
		TEST	ECX,ECX
		MOV	SYM_HASH_MOD,ECX
		JZ	L1$
		CALL	PUBDEF2
		XOR	EAX,EAX
		MOV	SYM_HASH_MOD,EAX
		RET

L1$:
		PUSH	EAX
		CALL	DO_DEFINE_MODULE
		POP	EAX
		JMP	LPUBDF1

LPUBDF32	LABEL	PROC

		MOV	AL,MASK BIT_32
		JMP	LPUBDF1

PUBDEF32	LABEL	PROC

		MOV	AL,MASK BIT_32
		JMP	PUBDEF1

LPUBDF		ENDP

PUBDEF		PROC
		;
		;DS:SI OF COURSE IS PUBDEF RECORD POINTER...
		;
		;FIRST IS GROUP INDEX, THEN SEGMENT INDEX (OPTIONAL FRAME)
		;
		;THEN ANY NUMBER OF PUBLIC SYMBOL DECLARATIONS
		;
if	fg_phar
		MOV	AL,BPTR DEFAULT_SIZE
else
		MOV	AL,0
endif

PUBDEF1::

PUBDEF2		LABEL	PROC

		MOV	PUB_SIZE,AL
		MOV	EAX,CURNMOD_GINDEX
		MOV	PUB_TYPE,NSYM_RELOC		;DEFAULT SYMBOL TYPE
		TEST	EAX,EAX
		JZ	PUB_HELP
PUB_HELP_RET:
		NEXT_INDEX	L1	;GET GROUP_INDEX
		MOV	ECX,EAX
		NEXT_INDEX	L2	;GET SEGMENT_INDEX
		MOV	EDX,EAX
		OR	EAX,ECX		;IF SI & GI ARE ZERO, ITS ASEG
		JZ	PUB_CONST
		;
		; CONVERT INDEXES TO POINTERS
		;
		MOV	EAX,ECX
		TEST	ECX,ECX
		JZ	NO_GROUP
		CONVERT_LINDEX_EAX_EAX	GROUP_LARRAY,EDI
NO_GROUP:
		MOV	PUB_GROUP_GINDEX,EAX
		MOV	EAX,EDX
		TEST	EDX,EDX
		JZ	NO_SEGMENT
		;No borland bugs
		;CMP	EAX,16K
		;JA	PUBDEF_MVIRDEF
PUBDEF_NVIRDEF:
		CONVERT_LINDEX_EAX_EAX	SEGMOD_LARRAY,EDI
PUBDEF_YVIRDEF:
		MOV	PUB_SEGMOD_GINDEX,EAX
		;
		;THESE MUST BE BOTH ASEG OR BOTH RELOCATABLE
		;IF BOTH ASEG, HANDLE LIKE PUB_ABS
		;
		CONVERT	EAX,EAX,SEGMOD_GARRAY
		CMP	[EAX].SEGMOD_STRUCT._SM_ALIGN,0
		JNZ	PUB_CHECK_1
		MOV	PUB_TYPE,NSYM_ASEG
		JMP	PUB_ABS1

PUB_HELP:
		CALL	DO_DEFINE_MODULE
		JMP	PUB_HELP_RET

		DOLONG	L1
		DOLONG	L2

PUBDEF_MVIRDEF:
		PUSH	EAX
		CONVERT_MYCOMDAT_EAX_ECX
		POP	EAX
		JC	PUBDEF_NVIRDEF
		TEST	[ECX].MYCOMDAT_STRUCT._MCD_FLAGS,MASK MCD_KEEPING_THIS
		JZ	IGNORE_PUBDEF
		MOV	EAX,[ECX].MYCOMDAT_STRUCT._MCD_SEGMOD_GINDEX
		JMP	PUBDEF_YVIRDEF


PUB_CONST:
		;
		;GET FRAME, THEN SHIFT IT 4 BITS, SET ASEG FLAG
		;
		MOV	EAX,[ESI]
		ADD	ESI,2
		MOV	PUB_TYPE,NSYM_CONST
		AND	EAX,0FFFFH
		JNZ	PC_1

		MOV	PUB_GROUP_GINDEX,EAX
		MOV	PUB_SEGMOD_GINDEX,EAX
PUB_ABS1:
PUB_CHECK_1:
		CALL	PUB_CHECK
		RET

NO_SEGMENT:
		MOV	AX,MUST_HAVE_SEGMENT_ERR
		CALL	ERR_RET
IGNORE_PUBDEF:
		RET

PC_1:
		MOV	AX,CONST_FRAME_ERR
		CALL	ERR_RET
		JMP	PUB_CHECK_1

PUBDEF		ENDP

		END

